package com.dragon.app.concurrent;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * 
 * <p>
 * class: CallableTest
 * </p>
 * <p>
 * Description: 测试callable
 * </p>
 * 
 * @author SmallDragon
 * @date 2019年5月6日
 *
 */
public class CallableTest {

	public static class MyTask implements Callable<Integer> {
		@Override
		public Integer call() throws Exception {
			System.out.println("do something...");
			return 1024;
		}
	}

	public static void main(String[] args) throws Exception {

		Callable<Integer> callable = new MyTask();
		FutureTask<Integer> futureTask = new FutureTask<Integer>(callable);
		new Thread(futureTask).start();

		TimeUnit.SECONDS.sleep(2);
		
		System.out.println(futureTask.get());

	}

}
